import { request } from '@/framework/utils/request-jdz';
import { getMd5 } from '@/libs/utils';
export const commonSearch = (params) => {
  return request(
    {
      url: '/common/cfg/no-paging',
      method: 'get',
      params,
    },
    {
      isGetDataDirectly: false,
    },
  );
};

export const commonDelete = (id) => {
  return request(
    {
      url: `/common/cfg/${id}`,
      method: 'delete',
    },
    {
      isGetDataDirectly: false,
    },
  );
};
export const commonUpdate = (params) => {
  return request(
    {
      url: `/common/cfg/${params.id}`,
      method: 'put',
      data: params,
    },
    {
      isGetDataDirectly: false,
    },
  );
};

export const commonAdd = (params) => {
  return request(
    {
      url: '/common/cfg',
      method: 'post',
      data: params,
    },
    {
      isGetDataDirectly: false,
    },
  );
};
export const getInputOutData = (type, params) => {
  return request(
    {
      url: `/common/opt/statistics/month-inout/${type}`,
      method: 'get',
      params,
    },
    {
      isGetDataDirectly: false,
    },
  );
};

/**
 * 词语联想
 * @param {*} type
 * @param {*} word
 * @param {*} size
 */
export const getWordAssociative = (type, word, size) => {
  return request(
    {
      url: `/search/associative/${type}/${word}`,
      method: 'get',
      params: {
        pageSize: size,
      },
    },
    {
      isGetDataDirectly: false,
    },
  );
};

// 样本溯源
export const queryTrace = (params) => {
  return request(
    {
      url: '/common/opt/statistics/trace',
      method: 'post',
      data: params,
    },
    {
      isGetDataDirectly: false,
    },
  );
};

// 客户端安装包上传
export const uploadFile = (params) => {
  return request(
    {
      url: '/file/upload-static',
      method: 'post',
      data: params,
      headers: { 'Content-type': 'multipart/form-data' },
    },
    {
      isGetDataDirectly: false,
    },
  );
};
// 备份上传
export const uploadBackup = (params) => {
  return request(
    {
      url: '/backup/restore',
      method: 'post',
      data: params,
      headers: {
        'Content-type': 'multipart/form-data',
        'Params-Sign': getMd5({ url: '/backup/restore' }, 'application/json;charset=UTF-8'),
      },
    },
    {
      isGetDataDirectly: false,
    },
  );
};

export const commonBatchUpdate = (params: { list: any[] }) => {
  return request(
    {
      url: '/common/cfg/batch-update',
      method: 'put',
      data: params,
    },
    {
      isGetDataDirectly: false,
    },
  );
};
